package rmi;

import static Common.Types.* ;
import heap.ResultSchema;

import java.sql.Types ;
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;


@SuppressWarnings("serial")
public class RemoteMetaDataImpl extends UnicastRemoteObject implements RemoteMetaData {
	private ResultSchema sch;

	public RemoteMetaDataImpl( ResultSchema sch ) throws RemoteException {
		this.sch = sch;
	}

	public int getColumnCount() throws RemoteException {
		return sch.size() ; 
	}

	public String getColumnName(int column) throws RemoteException {
		return sch.get( column - 1 ).name ;
	}

	public int getColumnType(int column) throws RemoteException {
		switch (sch.get( column - 1 ).type){
		case BLOB: return Types.BLOB;
		case BOOLEAN: return Types.BOOLEAN ;
		case CHAR: return Types.CHAR ;
		case DATETIME: return Types.DATE ;
		case DECIMAL: return Types.DECIMAL ;
		case FLOAT: return Types.FLOAT ;
		case INT: return Types.INTEGER ;
		case TIMESTAMP: return Types.TIMESTAMP ;
		case VARCHAR: return Types.VARCHAR ;
		default : return 1234 ; 
		}
	}

	public int getColumnDisplaySize(int column) throws RemoteException {
		switch (sch.get( column - 1 ).type){
		case BLOB: return 10 ;
		case BOOLEAN: return 2 ;
		case CHAR: return 2 ;
		case DATETIME: return 8 ;
		case DECIMAL: return 8 ;
		case FLOAT: return 8 ;
		case INT: return 6 ;
		case TIMESTAMP: return 8 ;
		case VARCHAR: return 10 ;
		default : return 0 ; 
		}
	}
}
